package com.wc.AlgoOJ.LQ1012_扫地机器人;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2024/3/16 22:18
 * @description http://43.138.190.70:8888/p/LQ1012
 */
public class Main {
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 100010;
    static int[] a = new int[N];
    static int n, k;

    public static void main(String[] args) {
        n = sc.nextInt();
        k = sc.nextInt();
        for (int i = 1; i <= k; i++) a[i] = sc.nextInt();
        Arrays.sort(a, 1, k + 1);
        int l = 1, r = 200000;
        while (l < r) {
            int mid = l + r >> 1;
            if (check(mid)) r = mid;
            else l = mid + 1;
        }
        out.println(l);
        out.flush();
    }

    static boolean check(int mid) {
        // end表示该打扫的位置
        int end = 1;
        for (int i = 1; i <= k; i++) {
            // a[i] - end表示，a[i]到达end的距离 * 2,就是回来的距离
            if ((a[i] - end) * 2 > mid) return false;
            // 表示该打扫的距离在a[i]的右侧，直接往右边走就好了
            if (end > a[i]) {
                end = Math.max(end, a[i] + mid / 2 + 1);
            } else {
                // end表示当前位置，a[i] - end 表示到达当前该扫的位置,mid - (a[i] - end) * 2 表示回到a[i]还剩的时间，原理同上了
                end = a[i] + (mid - (a[i] - end) * 2) / 2 + 1;
            }
        }
        return end > n;
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}